import argparse

from PIL import Image
import os


def resample_images(folder_path, output_folder, scale_factor):
    for filename in os.listdir(folder_path):
        if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif')):
            img_path = os.path.join(folder_path, filename)
            img = Image.open(img_path)

            # 计算新尺寸
            new_size = tuple([int(dim * scale_factor) for dim in img.size])

            img = img.resize(new_size, Image.Resampling.LANCZOS)

            new_img_path = os.path.join(output_folder, filename)
            img.save(new_img_path)
            print(f"Resampled {filename} and saved to {new_img_path}")



def main():
    parser = argparse.ArgumentParser(description='Downsample the spliced and rendered image')
    parser.add_argument("--in_dir", type=str,
                        default="E:\\wafer52\\11866",
                        help="image dir")
    parser.add_argument("--out_dir", type=str,
                        default="E:\\wafer52\\11866_16nm",
                        help="output dir")
    parser.add_argument("--down_sample_ratio", type=float, default=0.5,
                        help="set the down_sample_ratio")

    args = parser.parse_args()
    resample_images(args.in_dir, args.out_dir, args.down_sample_ratio)

if __name__ == '__main__':
    main()